package cn.wrl.order.fallback.itemservice;

import cn.wrl.item.pojo.vo.MyCommentVO;
import cn.wrl.pojo.PagedGridResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Collections;
import java.util.Map;

/**
 * 降级逻辑
 */
@Slf4j
@Component
@RequestMapping("AAA1")
public class ItemCommonFallbackFactory implements FallbackFactory<ItemCommonFeignClient> {


    @Override
    public ItemCommonFeignClient create(Throwable throwable) {

        return new ItemCommonFeignClient() {
            @Override
            public PagedGridResult queryMyComments(String userId, Integer page, Integer pageSize) {
                log.info("进入ItemCommonFallbackFactory");
                MyCommentVO myCommentVO = new MyCommentVO();
                myCommentVO.setContent("正在加载中");
                PagedGridResult result = new PagedGridResult();
                result.setRows(Collections.singletonList(myCommentVO));
                result.setPage(1);
                result.setTotal(1);
                return result;
            }

            @Override
            public void saveComments(Map<String, Object> map) {

            }
        };
    }
}
